<!-- navigationDrawer.vue -->
<template>
  <div v-if="visible">
    <div class="custom-drawer2">
      <!-- 路线信息 -->
      <div class="route-info">
        <div class="route-item recommended">
          <div class="route-content">
            <span class="route-title">导览路线：</span>
            <span class="route-title" >{{ duration }}分钟</span>
            <span class="route-title" >  | {{ distance }}米</span>
          </div>
        </div>
      </div>


      <!-- ✅ 路径提示添加滚动容器 -->
      <div class="navigation-tips" v-if="navigationTips && navigationTips.length">
        <div class="tip-sentence">
          <template v-for="(tip, index) in navigationTips" :key="index">
            <span
                class="tip-text"
                :style="{ color: tip.color || '#555' }"
            >{{ tip.text }}</span>
            <span class="tip-arrow" v-if="index < navigationTips.length - 1"> ➔ </span>
          </template>
        </div>
        <div class="system-notice">
          (本系统仅提供静态虚拟导引)
        </div>

      </div>


      <!-- 切换楼层按钮 -->
      <button v-if="!isSameFloor" class="switch-floor-button" @click="switchFloor">切换楼层</button>
    </div>
  </div>
</template>


<script setup>
import { defineProps, defineEmits, ref, onMounted, watch, nextTick } from 'vue';

const props = defineProps({
  visible: Boolean,
  startPoint: Object,
  endPoint: Object,
  distance: Number,
  duration: Number,
  navigationTips: {
    type: Array,
    default: () => []
  },
  isSameFloor: Boolean
});


const emit = defineEmits(['switch-floor', 'height-change']);

// 预定义两种高度
const HEIGHT_WITHOUT_BUTTON = 160; // 不显示切换按钮时的高度
const HEIGHT_WITH_BUTTON = 220;    // 显示切换按钮时的高度

// 报告预定义高度
const reportHeight = () => {
  if (props.visible) {
    // 根据是否显示切换楼层按钮来决定报告哪个高度
    const height = props.isSameFloor ? HEIGHT_WITHOUT_BUTTON : HEIGHT_WITH_BUTTON;
    console.log('Emitting height-change with predefined height:', height);
    emit('height-change', height);
  }
};

// 监听可见性变化，报告高度
watch(() => props.visible, (newVal) => {
  console.log('NavigationDrawer visible changed:', newVal);
  if (newVal) {
    // 使用 nextTick 确保 props 已更新
    nextTick(() => {
      reportHeight();
    });
  }
});

// 监听影响高度的属性变化
watch(() => [
  props.isSameFloor,
  props.navigationTips?.length > 0 // 只关心是否有提示，不关心具体数量
], ([isSameFloor, hasTips]) => {
  console.log('NavigationDrawer content changed:', {
    isSameFloor,
    hasTips
  });
  reportHeight();
}, { deep: true });

// 组件挂载时报告初始高度
onMounted(() => {
  console.log('NavigationDrawer mounted, visible:', props.visible);
  reportHeight();
});
const switchFloor = () => {
  emit('switch-floor');
};
</script>


<style scoped>
.navigation-tips {
  width: 100%;
  max-height: 120px; /* 限制最大高度 */
  overflow-y: auto; /* 启用垂直滚动 */
  padding: 12px;
  background-color: #f9f9f9;
  border: 1px solid #eee;
  border-radius: 8px;
  font-size: 14px;
  color: #333;
  margin: 16px 0;
}

/* 可选：添加滚动条样式 */
.navigation-tips::-webkit-scrollbar {
  width: 6px;
}

.navigation-tips::-webkit-scrollbar-thumb {
  background-color: #ccc;
  border-radius: 3px;
}

.navigation-tips::-webkit-scrollbar-thumb:hover {
  background-color: #aaa;
}

.switch-floor-button {
  width: 90%;
  max-width: 400px;
  padding: 14px 0;
  background: linear-gradient(135deg, #007bff, #0056b3);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 86, 179, 0.2);
  transition: all 0.3s ease;
  margin-top: 16px;
  text-transform: uppercase;
}

.switch-floor-button:hover {
  background: linear-gradient(135deg, #0069d9, #004085);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0, 86, 179, 0.3);
}

.switch-floor-button:active {
  transform: translateY(0);
  box-shadow: 0 2px 8px rgba(0, 86, 179, 0.2);
}

.custom-drawer2 {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #fff;
  border-top: 1px solid #ddd;
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.12);
  z-index: 9999;
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.route-info {
  width: 100%;
  display: flex;
  justify-content: space-between;
  margin-bottom: 0px;
}

.route-item {
  flex: 1;
  text-align: center;
  padding: 0px;
  border: 1px solid #ddd;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0px; /* 确保有足够的垂直空间 */
}

.recommended .route-title {
  color: #007bff;
}

.route-title {
  font-size: 15px;
  margin-bottom: 0px;
}

.route-details {
  font-size: 14px;
  color: #555;
}

.navigation-options {
  width: 100%;
  display: flex;
  justify-content: space-around;
  margin-bottom: 16px;
}

.option {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.option img {
  width: 32px;
  height: 32px;
  margin-bottom: 4px;
}

.option span {
  font-size: 12px;
  color: #666;
}

.start-navigation {
  width: 100%;
  padding: 12px 0;
  background-color: #007bff;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 16px;
}

.start-navigation:hover {
  background-color: #0056b3;
}
.navigation-tips {
  width: 100%;
  max-height: 120px;
  overflow-y: auto;
  padding: 12px;
  background-color: #f9f9f9;
  border: 1px solid #eee;
  border-radius: 8px;
  font-size: 14px;
  color: #333;
  margin: 16px 0;
}


.system-notice {
  text-align: center;
  font-size: 12px;
  color: #000000;
  margin: 8px 0;
  padding: 4px 0;
}

.tip-sentence {

  display: flex; /* 启用 Flexbox 布局 */
  align-items: center; /* 让所有子元素垂直居中对齐 */
  flex-wrap: wrap; /* 允许换行，以防句子太长 */
  line-height: 1.6;
  word-wrap: break-word;
  white-space: normal;
  width: 100%;
}

.tip-text {
  display: inline;
  color: #555;
}

.tip-arrow {
  /* 1. 使用最粗的字重 */
  font-weight: 900; /* 'black' 的数值表示，比 'bold' 更粗 */

  /* 2. 进一步增大字体 */
  font-size: 22px;

  margin: 0 8px;
  display: inline-block;

  /* 3. 增强渐变对比度，让亮光更突出 */
  background: linear-gradient(
      90deg,
      #0060c0 20%, /* 加深主色 */
      #ffffff 50%, /* 将亮色改为纯白，形成强烈扫光感 */
      #0060c0 80%  /* 加深主色 */
  );

  background-size: 300% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;

  /* 4. 加快动画速度，让流动感更强 */
  animation: flow-light 1.5s linear infinite;
}

/* 定义流光动画 */
@keyframes flow-light {
  0% {
    /* 动画开始时，背景在最左侧 */
    background-position: 100% 0;
  }
  100% {
    /* 动画结束时，背景移动到最右侧，形成一个循环 */
    background-position: 0 0;
  }
}

/* 滚动条样式 */
.navigation-tips::-webkit-scrollbar {
  width: 6px;
}

.navigation-tips::-webkit-scrollbar-thumb {
  background-color: #ccc;
  border-radius: 3px;
}

.navigation-tips::-webkit-scrollbar-thumb:hover {
  background-color: #aaa;
}

.route-content {
  width: fit-content;
  max-width: 300px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 8px 20px;
  border-radius: 30px;
}



</style>
